// SM3, GB/T 32905-2016 信息安全技术 SM3密码杂凑算法
// bobwxc@yeah.net, 2023
// Public domain

#include <stdio.h>

#include "sm3.h"

int main()
{
    unsigned char m[5] = "abc";
    unsigned char digest[32];
    sm3_once_calcu(m, 3, digest);
    char hex[65] = {0};
    sm3_hexdigest(digest, hex);
    printf("%s\n", hex);

    unsigned char m1[65] = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd";
    unsigned char digest1[32];
    sm3_once_calcu(m1, 64, digest1);
    char hex1[65] = {0};
    sm3_hexdigest(digest1, hex1);
    printf("%s\n", hex1);

    unsigned char digest5[32];
    unsigned char m3[59] = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab";
    sm3_once_calcu(m3, 58, digest5);
    char hex5[65] = {0};
    sm3_hexdigest(digest5, hex5);
    printf("%s\n", hex5);

    sm3_t h;
    sm3_init(&h);
    sm3_update(&h, "a", 1);
    sm3_update(&h, "b", 1);
    sm3_update(&h, "c", 1);
    unsigned char digest2[32];
    sm3_digest(&h, digest2);
    char hex2[65] = {0};
    sm3_hexdigest(digest2, hex2);
    printf("%s\n", hex2);

    sm3_t h1;
    sm3_init(&h1);
    sm3_update(&h1, m1, 64);
    unsigned char digest3[32];
    sm3_digest(&h1, digest3);
    char hex3[65] = {0};
    sm3_hexdigest(digest3, hex3);
    printf("%s\n", hex3);

    sm3_t h2;
    sm3_init(&h2);
    sm3_update(&h2, m3, 58);
    unsigned char digest4[32];
    sm3_digest(&h2, digest4);
    char hex4[65] = {0};
    sm3_hexdigest(digest4, hex4);
    printf("%s\n", hex4);

    return 0;
}

/*
> .\sm3_test.exe
66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0
debe9ff92275b8a138604889c18e5a4d6fdb70e5387e5765293dcba39c0c5732
56771e65b69902d76af4ff47834cf6d15d80dc24ec5aeb19d55e272ab4c2db5b
66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0
debe9ff92275b8a138604889c18e5a4d6fdb70e5387e5765293dcba39c0c5732
56771e65b69902d76af4ff47834cf6d15d80dc24ec5aeb19d55e272ab4c2db5b
*/
